var util = require('../../utils/util.js');
var ajax = require('../../utils/ajax.js');
var common = require('../../utils/common.js');
var MPage = require('../MPage.js');
var app = getApp();

Page(common.extendPage(MPage, {
    data: {
        winHei: 0,
        dataLoaded: false,
        userInfo: {},
        isLoign: !!app.getUserSid(),
        phoneNumber: '',
        isDisclaimer: false
    },

    onLoad: function() {
        this.setData({
            winHei: app.getWinHei()
        });
    },

    onShow() {
        var that = this;
        app.getUserInfo(function(userInfo) {
            that.setData({
                isLoign: !!app.getUserSid(),
                userInfo: userInfo,
                dataLoaded: true,
                phoneNumber: app.getShopTel()
            });
        })
    },
    /**
     * 页面跳转
     */
    _jump(evt) {
        var ty = evt.currentTarget.dataset.ty;
        var formId = evt.detail.formId;
        var isDisclaimer = evt.currentTarget.dataset.isDisclaimer;

        if (!isDisclaimer) {
            if (!this.data.isLoign) {
                wx.navigateTo({
                    url: '/pages/login/login'
                });
                return;
            }
        }

        var dataset = evt.currentTarget.dataset;
        var openType = dataset['openType'];
        var url = dataset.url;

        if (openType == 'navigate' || !openType) {
            openType = 'navigateTo';
        }

        wx[openType]({
            url
        });
        common.submitForm(formId);
    },
    /**
     * 联系客服
     */
    _tel() {
        var phoneNumber = this.data.phoneNumber;
        wx.makePhoneCall({
            phoneNumber //仅为示例，并非真实的电话号码
        })
    }
}));